import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'state.dart';

class WebViewLogic extends GetxController {
  final WebViewState state = WebViewState();
  var webController = WebViewController();
  late WebViewConfig config;
  @override
  void onInit() {
    super.onInit();
    webController.setJavaScriptMode(JavaScriptMode.unrestricted);
    config = Get.arguments as WebViewConfig;
    if (config.type == WebViewConfigType.url) {
      webController.loadRequest(Uri.parse(config.urlOrHtml));
    } else {
      webController.loadHtmlString(config.urlOrHtml);
    }
  }
}

class WebViewConfig {
  final WebViewConfigType type;
  final String urlOrHtml;
  final String title;

  WebViewConfig(
      {required this.type, required this.urlOrHtml, required this.title});
}

enum WebViewConfigType { url, html }
